﻿@page "/"

<PageTitle>Index</PageTitle>

<button class="btn btn-primary" @onclick="ShowForm">新增</button>

<table class="table table-hover">
    <thead>
        <tr>
            <th>Id</th>
            <th>姓名</th>
            <th>邮箱</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        @if (IsLoading) 
        {
            <tr>
                <td colspan="4" class="text-center">数据加载中...</td>
            </tr>
        }
        @foreach (var item in Users)
        {
            <tr>
                <td>@item.Id</td>
                <td>@item.Name</td>
                <td>@item.Email</td>
                <td>
                    <button class="btn btn-outline-info" @onclick="e=>Edit(item.Id)">编辑</button>
                    <button class="btn btn-danger" n @onclick="e=>Delete(item.Id)">删除</button>
                </td>
            </tr>
        }
    </tbody>
</table>

@if(IsShowingForm)
{
    <div class="container mt-5">
    <EditForm Model="Model" OnValidSubmit="SubmitAsync">
        <div class="row">
            <label class="col-form-label col-2">
                姓名
            </label>
            <div class="col-10">
                <InputText @bind-Value="Model.Name" class="form-control"/>
            </div>
        </div>
        <div class="row mt-3">
            <label class="col-form-label col-2">
                邮箱
            </label>
            <div class="col-10">
                <InputText @bind-Value="Model.Email" class="form-control"/>
            </div>
        </div>
        <div class="row mt-5">
            <button class="btn btn-primary w-25" type="submit">提交</button>
        </div>
        </EditForm>
    </div>
}